/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package maze;

import java.awt.*;
import javax.swing.*;

/**
 *
 * @author Iskandar Sarkawi
 */
public class MazeGUI extends JFrame{

    private ImagePanel imgPanel;
    JLabel statusLabel;

    public MazeGUI(Maze m){

        super("Maze Robot - Game of the year ");
        this.setSize(850, 650);

        imgPanel = new ImagePanel(m);

        //set content panel to BorderLayout
        Container contentPane = this.getContentPane();
        contentPane.setLayout(new BorderLayout());

        

//        JButton[] navigationBtn = new JButton[5];
//
//        navigationBtn[0] = new JButton("/\\");
//        navigationBtn[1] = new JButton("<");
//        navigationBtn[2] = new JButton(">");
//        navigationBtn[3] = new JButton("\\/");
//        navigationBtn[3] = new JButton("Stay");

        //JPanel[] navigationBtnHolder = new JPanel[5];


        //Directional button panel
        JPanel directionPanel = new JPanel();
        directionPanel.setLayout(new GridLayout(3,3));
        //directionPanel.setPreferredSize(new Dimension(200,200));

        JButton navigationBtnUp = new JButton("Up");
        navigationBtnUp.addActionListener(m);
        JPanel navigationBtnHolderUp = new JPanel();
        navigationBtnHolderUp.add(navigationBtnUp);

        JButton navigationBtnLeft = new JButton("Left");
        navigationBtnLeft.addActionListener(m);
        JPanel navigationBtnHolderLeft = new JPanel();
        navigationBtnHolderLeft.add(navigationBtnLeft);

        JButton navigationBtnStay = new JButton("Stay");
        navigationBtnStay.addActionListener(m);
        JPanel navigationBtnHolderStay = new JPanel();
        navigationBtnHolderStay.add(navigationBtnStay);

        JButton navigationBtnRight = new JButton("Right");
        navigationBtnRight.addActionListener(m);
        JPanel navigationBtnHolderRight = new JPanel();
        navigationBtnHolderRight.add(navigationBtnRight);

        JButton navigationBtnDown = new JButton("Down");
        navigationBtnDown.addActionListener(m);
        JPanel navigationBtnHolderDown = new JPanel();
        navigationBtnHolderDown.add(navigationBtnDown);
        

        //add into the directional Pad
        directionPanel.add(new JPanel()); // Add empty space
        directionPanel.add(navigationBtnHolderUp);
        directionPanel.add(new JPanel()); // Add empty space
        directionPanel.add(navigationBtnHolderLeft);
        directionPanel.add(navigationBtnHolderStay);
        directionPanel.add(navigationBtnHolderRight);
        directionPanel.add(new JPanel()); // Add empty space
        directionPanel.add(navigationBtnHolderDown);
        directionPanel.add(new JPanel()); // Add empty space
        
        JPanel directionPanelHolder = new JPanel();
        //directionPanelHolder.setPreferredSize(new Dimension(200,200));
        directionPanelHolder.add(directionPanel);

        //Reset and Undo Button
        JButton resetBtn = new JButton("Reset");
        resetBtn.addActionListener(m);

        JButton undoBtn = new JButton("Undo");
        undoBtn.addActionListener(m);

        JPanel resetAndUndoBtnHolder = new JPanel();
        resetAndUndoBtnHolder.add(resetBtn);
        resetAndUndoBtnHolder.add(undoBtn);
        // ---- End of Reset and Undo Button

        //Game status panel
        statusLabel = new JLabel("Game Status");
        JPanel statusPanel = new JPanel();
        statusPanel.add(statusLabel);

        JPanel leftPanel = new JPanel();
        int numRows = 0; // 0 for unlimited number of rows
        leftPanel.setLayout(new GridLayout(numRows, 1));
        leftPanel.setPreferredSize(new Dimension(220,350));
        leftPanel.setMaximumSize(new Dimension(220,350));
        leftPanel.add(directionPanelHolder);        
        leftPanel.add(resetAndUndoBtnHolder);
        leftPanel.add(statusPanel);

        //Finally add them to the content panel of the frame
        contentPane.add(leftPanel, BorderLayout.WEST);
        contentPane.add(imgPanel, BorderLayout.CENTER);
        

        this.setVisible(true);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setResizable(false);
        this.pack();
    }

    public void setStatus(String text){
        statusLabel.setText(text);
    }

    public void updateGraphics(){
        imgPanel.repaint();
    }

}
